package com.monas.client;

import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

import com.monas.client.database.MonasResourceDatabase;
import com.monas.client.view.AdministrationView;
import com.monas.client.view.CPUView;
import com.monas.client.view.HarddiskView;
import com.monas.client.view.MainView;
import com.monas.client.view.MemoryView;

public class Perspective implements IPerspectiveFactory {

	private IFolderLayout folder;

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
		layout.setFixed(true);

		folder = layout.createFolder("master", IPageLayout.TOP, 1.0f,
				editorArea);

		/**
		 * Tambahkan view.
		 */
		addViewId(layout, MainView.ID);
		addViewId(layout, CPUView.ID);
		addViewId(layout, MemoryView.ID);
		addViewId(layout, HarddiskView.ID);

		try {
			MonasResourceDatabase database = MonasResourceDatabase
					.getInstance();
			if (database.isAdmin()) {
				addViewId(layout, AdministrationView.ID);
			}
		} catch (Exception e) {
		}

	}

	private void addViewId(IPageLayout layout, String id) {
		folder.addView(id);
		layout.getViewLayout(id).setCloseable(false);
		layout.getViewLayout(id).setMoveable(false);
	}
}
